/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gameheart.client.sprite;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

/**
 *
 * @author DO-NGUYEN
 */
public abstract class Sprite {

    private BufferedImage image;
    private int width, height;
    protected int _x, _y;

    public Sprite() {
    }

//    public Sprite(int x, int y, int w, int h, BufferedImage image) {
//        _x = x;
//        _y = y;
//        width = w;
//        height = h;
//        this.image = image;
//    }
//    public Sprite 
    protected void Init(int x, int y, int w, int h, BufferedImage image) {
        _x = x;
        _y = y;
        width = w;
        height = h;
        this.image = image;
    }

    protected void Init(int x, int y, BufferedImage image) {
        _x = x;
        _y = y;
        if (image != null) {
            width = image.getWidth();
            height = image.getHeight();
        }
        this.image = image;
    }

//    public void setImage(String name) {
//        imageName = name;
//        image = imsLoader.loadImage(name);
//        if (image == null) {
//            System.out.println("No sprite image for " + imageName);
//            width = SIZE;
//            height = SIZE;
//        } else {
//            width = image.getWidth();
//            height = image.getHeight();
//        }
//    }
    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public void setX(int x) {
        _x = x;
    }

    public void setY(int y) {
        _y = y;
    }


    public int getX() {
        return _x;
    }

    public int getY() {
        return _y;
    }

    private Rectangle getMyRectangle() {
        return new Rectangle((int) _x, (int) _y, width, height);
    }

    public boolean isIntersec(Rectangle rec) {
        Rectangle myRect = getMyRectangle();
        if (myRect.intersects(rec)) {
            return true;
        }
        return false;
    }

    public void draw(Graphics g) {
        if (image != null) {
            g.drawImage(image, (int) _x, (int) _y, width, height, null);
        }

    }
//    public void draw(Graphics g, double  rate) {
//        imsLoader.drawResizedImage(g, image, (int) locx, (int) locy, rate, rate);
//
//    }
//    @Override
//    public Object clone() {
//        Sprite sprite = new Sprite();
//        sprite._x = this._x;
//        sprite._y = this._y;
//        sprite.height = this.height;
//        sprite.width = this.width;
//        sprite.isActive = this.isActive;
//        sprite.image = this.image;
//        return sprite;
//    }
}
